<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>js中prototype原型模型</title>
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
    <script type="text/javascript">
        $(function () {
            // 设置Bar的prototype属性为Foo的实例对象
            Bar.prototype = new Foo();
            Bar.prototype.foo = "Hello world";
//
//            // 修正Bar.prototype.constructor为Bar本身
//            Bar.prototype.constructor = Bar;

            // 创建Bar的一个新实例
            var testBar = new Bar();
            console.log(testBar.foo);
            console.log(testBar.value);
            testBar.fooMethod();

            // 创建Foo的一个新实例
            var testFoo = new Foo();
            console.log(testFoo.value);
            testFoo.fooMethod();

            forinDemo();
        });

        function Foo() {
            this.value = 42;
        }
        Foo.prototype = {
            fooMethod: function () {
                console.log("I`m in Foo function!");
            }
        };

        function Bar() {
        }

        /*
         * forin 循环
         * */
        function forinDemo() {
            Object.prototype.bar = 1;

            var foo = {moo: 2};

            for (var i in foo) {
                if (foo.hasOwnProperty(i)) {
                    console.log(i);
                }
            }
        }
    </script>
</head>
<body>

</body>
</html>